﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Web.MdAddress.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Web.MdAddress;
/// <summary>
/// 通过编号更新收货/发货地址服务
/// </summary>
public class UpdateMdAddressByIdWebService : ApiBase<RequestUpdateMdAddressByIdWebModel>
{
    /// <summary>
    /// 收货/发货地址仓储
    /// </summary>
    public MdAddressRep mdAddressRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdAddressModel();

        model.AddressId = Parameter.AddressId;
        model.Name = Parameter.Name;
        model.Phone = Parameter.Phone;
        model.Email = Parameter.Email;
        model.Region = Parameter.Region;
        model.RegionLabels = Parameter.RegionLabels;
        model.Country = Parameter.Country;
        model.Province = Parameter.Province;
        model.City = Parameter.City;
        model.District = Parameter.District;
        model.ZipCode = Parameter.ZipCode;
        model.Address = Parameter.Address;
        model.UserId = Parameter.UserId;
        model.AddressType = Parameter.AddressType;
        model.IsDefault = Parameter.IsDefault;
        model.Status = Parameter.Status;
        model.UpdateBy = userKey?.ToString();
        model.UpdateTime = DateTime.Now;

        var res = mdAddressRep.UpdateMdAddressById(model);

        if (res > 0)
        {
            Result.Data = mdAddressRep.GetMdAddressById(model.AddressId);
        }
        else
        {
            Result.Data = res;
        }
    }
}

